﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EventRegistration;


public partial class Revenue_ReportForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!CurrentData.RegistrationInfo.Completed) //If user not login, redirect to login page
            {
                Response.Redirect("../Register/Login.aspx");
            }

            //Set value for the first time page loading
            if (!IsPostBack)
            {
                DatePicker.Date = DateTime.Today;
                overallRadio.Checked = true;
            }
            
            //Check if user choose view overall statistic or view by date
            if (bydateRadio.Checked == true)
            {
                DatePicker.Enabled = true;
                RevenueDataSource.SelectCommand =
                    "SELECT Product.Model, (A.TotalQuantity * Product.Price) AS Revenue " +
                "FROM Product INNER JOIN " +
                "(SELECT ProductID, SUM(Quantity) " +
                "AS TotalQuantity FROM OrderScheduling WHERE StartDate='" +
                String.Format("{0:yyyy-MM-dd}", this.DatePicker.Date) +
                "' GROUP BY ProductID) " +
                "AS A ON A.ProductID = Product.ProductID;";
            }
            else
            {
                DatePicker.Enabled = false;
                RevenueDataSource.SelectCommand =
                    "SELECT Product.Model, (A.TotalQuantity * Product.Price) AS Revenue " +
                "FROM Product INNER JOIN " +
                "(SELECT ProductID, SUM(Quantity) " +
                "AS TotalQuantity FROM OrderScheduling " +
                "GROUP BY ProductID) " +
                "AS A ON A.ProductID = Product.ProductID;";
            }
        }

        protected void DatePicker_DateChanged(object sender, EventArgs e)
        {
        }
        protected void overallRadio_CheckedChanged(object sender, EventArgs e)
        {
        }
        protected void bydateRadio_CheckedChanged(object sender, EventArgs e)
        {
        }
}

